package com.cw.recommend.common

import com.cw.recommend.common.constant.SPARK_MASTER
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

object Runner {

  case class RunnerConfig(appName: String, master: String = SPARK_MASTER)


  def runSpark(f: SparkSession => Unit)(implicit runnerConfig: RunnerConfig): Unit = {
    val conf = new SparkConf()
      .setAppName(runnerConfig.appName)
      .setMaster(runnerConfig.master)

    val spark = SparkSession
      .builder()
      .config(conf)
      .getOrCreate()

    f(spark)

    spark.close()


  }


}
